package com.yitiao.base;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class AgentThreadInfoDemo {
    public static void main(String[] args) {
// 创建一个线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        // 获取ThreadMXBean实例
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

        // 在这里可以添加一些逻辑来获取线程池的运行情况
        // 例如，获取线程池中的活动线程数、线程池大小等信息
        int activeThreadCount = threadMXBean.getThreadCount();
        int poolSize = executorService instanceof ThreadPoolExecutor ?
                ((ThreadPoolExecutor) executorService).getCorePoolSize() : -1;

        // 打印线程池的运行情况
        System.out.println("Active Threads: " + activeThreadCount);
        System.out.println("Pool Size: " + poolSize);

        // 关闭线程池
        executorService.shutdown();
    }
}
